package com.unytech.watersoil.entity.security;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.GenericGenerator;

import com.unytech.watersoil.entity.BaseObject;

/**
 * 权限组实体类
 * @author LONG
 *
 */
@Entity @Table(name="T_PERMISSIONGROUP")
@GenericGenerator(name="uuidpk",strategy="uuid")
public class PermissionGroup extends BaseObject{
	@Id @GeneratedValue(generator="uuidpk")
	@Column(length=50,nullable=false)
    private String permgroupid;                //权限组ID
	
	@Column(length=30,nullable=false)
    private String permgroupname;              //权限组名称
	
	@Column(nullable=false)
	private Integer enableallot = 0;           //是否允许分配隶属权限，默认为不允许    
	
    @Temporal(TemporalType.TIMESTAMP) @Column(nullable=false)
    private Date permregdate = new Date();     //权限组注册日期
    
    @ManyToMany(cascade=CascadeType.REFRESH)
    @JoinTable(name="permissions_permissionGroup")                             //定义关联表
    private Set<Permission> permissions;       //权限组所和权限之间的多对多关系映射
    
	//级联刷新，级联保存，级联更新；懒加载（一对多关系，多的一方默认就是延迟加载，所以可以不设置fetch；关系被维护端，由User类中的unit字段来维护）
	@OneToMany(cascade={CascadeType.REFRESH,CascadeType.PERSIST,CascadeType.MERGE},fetch=FetchType.LAZY,mappedBy="permgroup")
    private Set<User> users;                   //隶属于此权限组下的所有用户，规定每个人只能隶属于一个权限组，所以是一对多关系
    
	public String getPermgroupid() {
		return permgroupid;
	}
	public void setPermgroupid(String permgroupid) {
		this.permgroupid = permgroupid;
	}
	public String getPermgroupname() {
		return permgroupname;
	}
	public void setPermgroupname(String permgroupname) {
		this.permgroupname = permgroupname;
	}
	public Set<Permission> getPermissions() {
		return permissions;
	}
	public void setPermissions(Set<Permission> permissions) {
		this.permissions = permissions;
	}
	public void setPermregdate(Date permregdate) {
		this.permregdate = permregdate;
	}
	public Date getPermregdate() {
		return permregdate;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	public Set<User> getUsers() {
		return users;
	}
	public void setEnableallot(Integer enableallot) {
		this.enableallot = enableallot;
	}
	public Integer getEnableallot() {
		return enableallot;
	}

}
